home *** CD-ROM | disk | FTP | other *** search
/ Clipper Collection / Clipper Collection.iso / clipper7 / nannws12.arc / KEYLOCK.ASM < prev    next >
Assembly Source File  |  1986-11-26  |  4KB  |  133 lines

  1.  
  2. ;    Title:    KEYLOCK.ASM
  3. ;    Author:    F. Ho 
  4. ;    Date:    28th May 1986
  5. ;    Syntax:    ? LOCKSTAT()
  6. ;    Note:    returns current status of the 4 "lock" keys in the form - ICNS
  7. ;
  8. ;    Revised PBaenziger, pbprograms, 1215 Lane, Kalamzoo, MI 49001
  9. ;    (616) 349-9720 (Evenings), 323-7392 (Days, 8-4:30 EDT)
  10. ;
  11. ;       Calling syntax:  1- ? LOCKSTAT()
  12. ;                        2- X = LOCKSTAT()
  13. ;
  14. ;       Returns a character type string in the form: "icns"
  15. ;
  16. ;       where:  i = insert lock key
  17. ;            c = caps lock key
  18. ;           n = num lock key
  19. ;            s = scroll lock key
  20. ;
  21. ;       If the returned string ("icns") displays any letters in upper
  22. ;       case, it means that that lock key has been "activated".
  23. ;
  24. ;       example:
  25. ;            - if the function returns: iCnS
  26. ;
  27. ;               - it means that the Caps Lock and
  28. ;              the Scroll Lock keys are ON
  29. ;
  30. public LOCKSTAT
  31. ;
  32. ;
  33. extrn  _RETC:far                       ; Clipper return character
  34. ;
  35. ;==================================================
  36. DGROUP    GROUP    DATASG
  37. datasg segment PUBLIC  'DATA'
  38. ;==================================================
  39. ;    
  40.                                   ; Table for following lock status:
  41.  
  42. LOCKTABLE   DB 'icns',0    ; All off Insert, Caps, Numlock, Scroll (not in org)
  43.             DB 'icnS',0    ;
  44.             DB 'icNs',0    ;
  45.             DB 'icNS',0    ;
  46.             DB 'iCns',0    ;
  47.             DB 'iCnS',0    ;
  48.             DB 'iCNs',0    ;
  49.             DB 'iCNS',0    ;
  50.             DB 'Icns',0    ;
  51.             DB 'IcnS',0    ;
  52.             DB 'IcNs',0    ;
  53.             DB 'IcNS',0    ;
  54.             DB 'ICns',0    ;
  55.             DB 'ICnS',0    ;
  56.             DB 'ICNs',0    ;
  57.             DB 'ICNS',0    ; All on
  58. ;
  59. ;
  60. ;==================================================
  61. datasg ends
  62. ;==================================================
  63. ;
  64. ;
  65. ;==================================================
  66. _prog  segment byte                ; byte aligned         
  67. assume cs:_prog,ds:DGROUP,es:NOTHING    ; original ->datasg
  68. ;==================================================
  69. ;
  70. LOCKSTAT    proc    far    ; far process
  71.         push    bp    ; not really needed on an IBM PC/AT - IBM
  72.                 ; BIOS does not change BP.  But in case of
  73.                 ; a badly behaved clone with inferior BIOS
  74.                 ; it may be good protection
  75.                 
  76.         mov    ah,02        ; request current shift status (into AL)
  77.         int    16h            ; issue keyboard input int
  78.  
  79.          ;Returns shift state in AL in upper nibble
  80.          ; 80h - Insert state
  81.          ; 40h - Caps Lock state
  82.          ; 20h - Num Lock state
  83.          ; 10h - Scroll Lock state
  84.  
  85.         ; The index value of the KEYBOARD FLAG is in the upper
  86.         ; nibble of AL.  To use it as a pointer, we have to divide it
  87.         ; by 16 (or shift it right 4 times, move it into the lower
  88.         ; nibble.  However, LOCKTABLE has 5 byte steps, so we have
  89.         ; to multiply back by 5.  One way to do it is:
  90.         ;    1 - Clear out the lower nibble, extend the returned
  91.         ;        byte to a word
  92.         ;    2 - shift right 2 times (divide by 4).  This is
  93.         ;        the same as dividing by 16, then multiplying
  94.         ;        by 4.  This is all that would be needed for a 
  95.         ;        4 byte step table. 
  96.         ;    3 - save this intermediate value in BL (or wherever)
  97.         ;    4 - shift right 2 more times for a total of 4
  98.         ;        right shifts (divided by 16)
  99.         ;    5 - add in the saved value from step 3.  This gives
  100.         ;        use the 5 byte step index in AX
  101.         ;    6 - add the value to the base offset of LOCKTABLE
  102.         ;        BX is now pointing to the correct entry,
  103.         ;        ready for transfer back to CLIPPER after pushing
  104.         ;        it and the segment value
  105.  
  106.         SUB AH, AH    ; Make a word value out of AL
  107.         AND AL, 0F0H    ; Clear out lower nibble
  108.         MOV CL, 2         ; Divide by 4 - 2 shift right
  109.         SHR AL, CL
  110.         MOV BL, AL    ; Save the divided by 4 value
  111.         SHR AL, CL    ; Divide by 4 - a total of 16
  112.         ADD AL, BL    ; Now we have the 5 byte a step index
  113.                     ; into LOCKTABLE in AX
  114.         LEA BX, LOCKTABLE    ; Get the base offset
  115.         ADD BX, AX        ; Now points to correct entry
  116.         MOV AX, DGROUP        ; And also the right segment
  117.         
  118.         ; restore stack to original position
  119.         pop    bp                    ; restore stack base pointer
  120.  
  121.         push    ax                    ; push AX (segment)
  122.         push    bx                    ; push BX (offset)
  123.         call    _RETC                ; call Clipper return for type CHAR
  124.          ADD SP, 4                    ; quicker
  125.  
  126.         ret                        ; far return
  127.  
  128. LOCKSTAT    endp                        ; end of process
  129. ;
  130. _prog    ends                        ; end of segment
  131.         end                        ; end of programme
  132.  
  133.